package com.zgjkhis.modules.system.service.impl;

import com.github.pagehelper.PageInfo;
import com.zgjkhis.common.service.impl.BaseServiceImpl;
import com.zgjkhis.domain.PageResult;
import com.zgjkhis.modules.system.domain.DrugCirculation;
import com.zgjkhis.modules.system.req.DrugCirculationReq;
import com.zgjkhis.modules.system.req.DrugCirculationToReq;
import com.zgjkhis.modules.system.resp.DrugCirculationDetailRes;
import com.zgjkhis.modules.system.service.DrugCirculationService;
import com.zgjkhis.modules.system.service.mapper.DrugCirculationMapper;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;

/**
 * @Author yzq
 * @Description 药品流转
 * @Date 2021/6/23 9:47
 * @Param
 * @return
 **/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "user")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class DrugCirculationServiceImpl extends BaseServiceImpl<DrugCirculationMapper, DrugCirculation> implements DrugCirculationService {

    private final DrugCirculationMapper drugCirculationMapper;

    /**
     * 分页查询流转药品数据
     * @param drugCirculationReq
     * @param pageable
     * @return
     */
    @Override
    public PageResult<DrugCirculation> queryAll(DrugCirculationReq drugCirculationReq, Pageable pageable) {
        getPage(pageable);
        List<DrugCirculation> drugCirculations = drugCirculationMapper.queryAll(drugCirculationReq);
        PageInfo<DrugCirculation> page = new PageInfo<>(drugCirculations);
        return PageResult.data(page, DrugCirculation.class);
    }

    @Override
    public PageResult<DrugCirculationDetailRes> queryCirculationAll(DrugCirculationToReq drugCirculationToReq, Pageable pageable) {
        getPage(pageable);
        List<DrugCirculationDetailRes> drugCirculations = drugCirculationMapper.queryCirculationAll(drugCirculationToReq);
        PageInfo<DrugCirculationDetailRes> page = new PageInfo<>(drugCirculations);
        return PageResult.data(page);
    }
}
